<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>服务前端</title>
</head>
<body>
<div align="center" id="tab">
    <table border="1px">
        <input type="checkbox" name="cartItemId" id="all">全选
    <#list cartItemList as cartItem>
            <tr>
                <td>${cartItem.busTeamName}${cartItem.busTeamId}</td>
                <td><input type="checkbox" name="cartItemId" value="${cartItem.cartItemId}"><img src="${cartItem.imageUrl}"></td>
                <td>${cartItem.productName}</td>
                <td>￥<span class="unitPrice" >${cartItem.price/cartItem.quantity}</span></td>
                <td><input type="hidden" value="${cartItem.cartItemId}" class="cartItemId"><button class="add">+</button><input type="text" class="quantity" value="${cartItem.quantity}"><button class="sub">-</button></td>
                <td>￥<span class="price">${cartItem.price}</span></td>
                <td><a href="/yyfn/trading/delServiceProductById?cartItemId=${cartItem.cartItemId}&type=0">删除</a></td>
            </tr>
        </#list>
    </table>
    <span>已选商品<i id="amount" style="color: red"></i>件</span>
    <span>合计：￥<i id="total" style="color: red"></i></span><br>
    <button id="submit">结算</button>
</div>
</body>
<script src="http://ajax.aspnetcdn.com/ajax/jquery/jquery-1.9.0.min.js"></script>
<script>
    $(function () {
        $(".add").click(function() {
            var t = $(this).parent().find('input[class*=quantity]');
            t.val(parseInt(t.val()) + 1);
            var t = $(this).parent().find('input[class*=quantity]').val();
            var cartItemId = $(this).parent().find('input[class*=cartItemId]').val();
            $.ajax({
                url:"/yyfn/trading/product/updateCartItem?cartItemId="+cartItemId+"&quantity="+t,
                type:"POST",
                cache:false,
                success:function (data) {
                    if(data == "ok") {
                        location.reload()
                    }
                }
            })
        })
        $(".sub").click(function() {
            var t = $(this).parent().find('input[class*=quantity]')
            var quantity = t.val();
            if(quantity != 1) {
                quantity--;
                t.val(quantity);
                var t = $(this).parent().find('input[class*=quantity]').val();
                var cartItemId = $(this).parent().find('input[class*=cartItemId]').val();
                $.ajax({
                    url:"/yyfn/trading/product/updateCartItem?cartItemId="+cartItemId+"&quantity="+quantity,
                    type:"POST",
                    cache:false,
                    success:function (data) {
                        if(data == "ok") {
                            location.reload()
                        }
                    }
                })
            }
        });
        $("#all").click(function () {
            $("[name=cartItemId]:checkbox").each(function(){
                $(this).attr("checked",true);
            });
            var total = 0;
            $(".price").each(function(){
                total += $(this).val();
            });
        });
        $("#submit").click(function(){
            var str="";
            $("[name=cartItemId]:checkbox:checked").each(function(){
                str+=$(this).val()+" ";
            });
        });
    })
</script>
</html>